// pages/birthdaylist/birthdaylist.js
const app = getApp()
const utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    pageNumber: 1,
    totalPages:0,
  },

  getlistFriend() {
    var that = this
    app.req({
      url: "blessmini/blesscommon/listFriend",
      data: {
        pageNumber: that.data.pageNumber,
        pageSize: 10,
      },
      method: "post",
      success: function (res) {
        if (res.code == 200) {
          for (var i in res.data.rows){
            res.data.rows[i].week = utils.getWeek(res.data.rows[i].birthday)
            res.data.rows[i].birthday = res.data.rows[i].birthday.substring(5,10)
          }
          that.setData({
            list: that.data.list.concat(res.data.rows),
            totalPages: res.data.totalPages
          })
          console.log('近期寿星', that.data.listFriend)
        }
      }
    })
  },
  topage(e){
    wx.navigateTo({
      url: '/pages/ordinaryDetails/ordinaryDetails?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      pageNumber:1,
      list:[]
    })
    that.getlistFriend()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.totalPages>this.data.pageNumber){
      this.setData({
        pageNumber:this.data.pageNumber+1
      })
      this.getlistFriend()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})